pub mod ast;
use std::time::{SystemTime, UNIX_EPOCH};

pub use ast::lexer;
pub use ast::Argument;
pub use ast::ArgumentName;
pub use ast::Command;
pub use ast::Input;
pub use ast::Token;

pub mod server;
use bytes::BytesMut;
pub use server::Server;

pub mod error;
pub use error::Error;

pub mod handler;

pub mod cache;

pub mod wal;

pub const MESSAGE_QUEUE_SIZE: usize = 1024 * 100;
pub const SEGMENT_SIZE: u64 = 1024 * 1024 * 10;
pub const BYTE_CAPACITY: usize = 1024 * 1024;
pub const MQ_PATH: &str = "/tmp/rust-mq";
pub const DEFAULT_FILENAME: &str = "0000000000000000";

#[derive(Debug, Clone)]
pub struct SendMessage {
    pub topic: String,
    pub partition: u16,
    pub buf: BytesMut,
    pub timestamp: u128,
}

impl SendMessage {
    pub fn new(topic: String, partition: u16, buf: BytesMut) -> Self {
        let timestamp = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis();
        SendMessage {
            topic,
            partition,
            buf,
            timestamp: timestamp,
        }
    }
}
